﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using pTools.cMethods;

namespace pTools.TuQiangPrint
{
    public partial class SelectCustomer : DevExpress.XtraEditors.XtraForm
    {
        DBHelper db = new DBHelper();
        public DbCustomer selectedCustomer;
        List<DbCustomer> customerList = new List<DbCustomer>();
        public SelectCustomer()
        {
            InitializeComponent();
        }
        private void SelectCustomer_Load(object sender, EventArgs e)
        {
            RefreshInterface();
        }
        void RefreshInterface()
        {
            var sql = "select * from fun_Customs_info where dataType = 'Cu' and status = 'Y' and baseCode = '" + CommonMethods.baseCode + "' ";

            var code = tb_customer.Text;
            var name = tb_customerName.Text;
            if (!string.IsNullOrEmpty(code))
            {
                sql += "and cuCode like '%" + code + "%'";
            }
            if (!string.IsNullOrEmpty(name))
            {
                sql += "and cuname like '%" + name + "%'";
            }

            var dt = db.getData(sql);

            customerList = CommonMethods.ConvertTo<DbCustomer>(dt);

            grid_customer.DataSource = customerList;
        }

        private void gridView_customer_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            selectedCustomer = customerList[gridView_customer.FocusedRowHandle];
            Close();
        }

        private void tb_EditValueChanged(object sender, EventArgs e)
        {
            RefreshInterface();
        }
    }
}